﻿using RoMBot.Scripting;

namespace RoMBot.Waypoints
{
    public class Waypoint
    {
        public float X { get; set; }

        public float? Y { get; set; }

        public float Z { get; set; }

        public string Name { get; set; }

        public string Code { get; set; }

        public WaypointType Type { get; set; }

        internal IWayPointScriptBase wayPointScriptBase;

        internal Waypoint() { }

        public Waypoint( float x, float z )
        {
            this.X = x;
            this.Z = z;
        }

        public Waypoint( float x, float z, float? y )
            : this( x, z )
        {
            this.Y = y;
        }

        public Waypoint( float x, float z, float? y, string code )
            : this( x, z )
        {
            this.Y = y;
            this.Code = code;
        }

        public Waypoint( float x, float z, string name )
            : this( x, z )
        {
            this.Name = name;
        }

        public Waypoint( float x, float z, string name, string code )
            : this( x, z, name )
        {
            this.Code = code;
        }

        public Waypoint( float x, float z, string name, string code, WaypointType type )
            : this( x, z, name, code )
        {
            this.Type = type;
        }

        public void Update() { }

        /// <summary>
        /// Executes Waipoint code if any.
        /// </summary>
        /// <remarks>
        /// The return value is not used "yet".
        /// </remarks>
        /// <returns>Returns an object.</returns>
        public object Execute()
        {
            return !this.HasAction ? null : this.wayPointScriptBase.Execute();
        }

        public bool HasAction
        {
            get { return this.wayPointScriptBase != null; }
        }

        public int Index { get; set; }

        public override string ToString()
        {
            return string.Format( "X: {0}, Y: {1}, Z: {2}", X, Y, Z );
        }
    }

    public enum WpFailReason
    {
        WfNone = 0,   // We didn't fail
        WfTarget = 1, // Failed waypoint because we have a target
        WfDist = 2,   // Broke because our distance somehow increased. It happens.
        WfStuck = 3,  // Failed waypoint because we are stuck on something.
        WfCombat = 4, // stopped waypoint because we are in combat
        WfPullback = 5 // Failed because pulled back to before last waypoint
    }
}